package com.comac.print.component.app.gatewayimpl.database.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.comac.print.component.app.dto.PrintRecordDTO;
import com.comac.print.component.app.gatewayimpl.database.dataobject.PrintRecordDO;
import com.comac.print.component.app.qry.PrintRecordQry;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 打印记录表 Mapper 接口
 * </p>
 *
 * @author yy
 * @since 2022-04-08
 */
public interface PrintRecordMapper extends BaseMapper<PrintRecordDO> {
    @Select("<script>" +
            "select " +
            "p.ID as ptId, " +
            "p.MP_ID as mpId, " +
            "p.SOURCE as source, " +
            "p.PRINT_PERSON as print_person, " +
            "p.PRINT_TIME as printTime, " +
            "p.DATA_SOURCE_URL as dataSourceUrl, " +
            "p.INPUT_PARAMETER_VALUE as inputParameterValue, " +
            "p.MESSAGE_SUBSCRIPTION_FLAG as messageSubscriptionFlag, " +
            "p.MESSAGE_TOPIC as messageTopic, " +
            "p.FAILURE_REASON as failureReason, " +
            "p.PRINT_URL as printUrl, " +
            "m.MP_NAME as mpName, " +
            "m.MP_NUMBER as mpNumber, " +
            "s.STATUS as status " +
            "from " +
            "	print_masterplate m " +
            "inner join " +
            "	print_record p on m.ID = p.MP_ID " +
            "inner join " +
            "	print_status s on s.PRINT_RECORD_ID = p.ID and s.IS_NEW = 1  " +
            "<where> " +
            "<if test=\"qry.ptId != null and qry.ptId != ''\">" +
            "     and p.ID = #{qry.ptId}" +
            "</if>" +
            "<if test=\"qry.source != null and qry.source != ''\">" +
            "     and p.SOURCE = #{qry.source}" +
            "</if>" +
            "<if test=\"qry.printPerson != null and qry.printPerson != ''\">" +
            "     and p.PRINT_PERSON like concat('%',#{qry.printPerson},'%')" +
            "</if>" +
            "<if test=\"qry.mpName != null and qry.mpName != ''\">" +
            "     and m.MP_NAME like concat('%',#{qry.mpName},'%')" +
            "</if>" +
            "<if test=\"qry.mpNumber != null and qry.mpNumber != ''\">" +
            "     and m.MP_NUMBER like concat('%',#{qry.mpNumber},'%')" +
            "</if>" +
            "<if test=\"qry.printTime != null and qry.printTime != ''\">" +
            "     and p.PRINT_TIME like concat('%',#{qry.printTime},'%')" +
            "</if>" +
            "<if test=\"qry.mpId != null and qry.mpId != ''\">" +
            "     and p.MP_ID = #{qry.mpId}" +
            "</if>" +
            "<if test=\"qry.status != null and qry.status != ''\">" +
            "     and s.STATUS = #{qry.status} " +
            "</if>" +
            "  and p.DELETE_FLAG = 0 " +
            "</where> " +
            "</script>")
    Page<PrintRecordDTO> qryPrintRecordList(Page page, @Param("qry") PrintRecordQry qry);

}
